import { _decorator, Component, director, Node, tween, v3 } from 'cc';
import *as cc from "cc";
import { AdComponent } from '../AdComponent';
import { MainGameUI } from '../MainGameUI';
import { AudioMgr, ENUM_CLIP } from '../Tool/AudioMgr';
import Util from '../Util';
import DatasSpace from '../Tool/DatasSpace';
import SkdComm from '../SkdComm';
const { ccclass, property } = _decorator;

@ccclass('AddTimePop')
export class AddTimePop extends Component {

  @property(Node)
  viewNode: Node = null;

  @property(Node)
  propBtn: Node = null;

  @property(Node)
  shareBtn:Node=null;

  private addTimeNum: number = 300;
  start() {
    console.log('时钟', DatasSpace.Instance.propNumArr[4])
    DatasSpace.Instance.gamePause = true;


    //this.propBtn.active = (DatasSpace.Instance.propNumArr[4] > 0);

  }
  openLose(num): void {
    if(this.shareBtn){
      if(num==0){
        this.shareBtn.active=true;
      }else{
        this.shareBtn.active=false;
      }
    }
    
  }

  protected onDestroy(): void {
    DatasSpace.Instance.gamePause = false;

  }

  update(deltaTime: number) {

  }

  shareAddTime(){
    SkdComm.Instance.shareTo(() => {
      MainGameUI.inst.timer = this.addTimeNum;
      MainGameUI.inst.startCountDown();
      this.btnCloseSetting();
      cc.game.emit('showWord');
    })
  }

  btnAddTimeByVideoAd() {
    AdComponent.Instance.loadVideoAd(0, (res) => {
      if (res) {
        MainGameUI.inst.timer = this.addTimeNum;
        MainGameUI.inst.startCountDown();
        this.btnCloseSetting();
        cc.game.emit('showWord');
      }
    });
    // if (DatasSpace.Instance.propNumArr[4] > 0) {
    //   DatasSpace.Instance.propNumArr[4] -= 1;
    //   DatasSpace.Instance.setPropNum();
    //   MainGameUI.inst.timer = this.addTimeNum;
    //   MainGameUI.inst.startCountDown();
    //   this.btnCloseSetting();
    //   cc.game.emit('showWord');
    // } else {
    //   AdComponent.Instance.loadVideoAd(0, (res) => {
    //     if (res) {
    //       MainGameUI.inst.timer = this.addTimeNum;
    //       MainGameUI.inst.startCountDown();
    //       this.btnCloseSetting();
    //       cc.game.emit('showWord');
    //     }
    //   });
    // }



  }

  btnQuitGame() {
    director.loadScene('Home');
    // this.btnCloseSetting();
    // Util.Instance.GloberLoadPrefab('Lose', 2, (res) => {
    //   let newNode = cc.instantiate(res);
    //   cc.find('UI').getChildByName('PopView').addChild(newNode);
    //   newNode.setPosition(0, 0, 0);
    //   //this.hideWord();
    // }, () => {

    // });
  }

  btnCloseSetting() {
    AudioMgr.Instance.play(ENUM_CLIP.Click);

    // AdComponent.Instance.instance.playAudio(2);
    // AdComponent.Instance.hide5X5customAd();
    tween(this.viewNode).to(0.5, { position: v3(0, this.viewNode.getPosition().y + 1600, 0) }, { easing: 'backInOut' }).call(() => {

      this.node.removeFromParent();
      this.node.destroy();
    }).start();
  }
}


